package com.wenyu.wenyuyuedu.adapter.homepagefragment;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;

import com.bumptech.glide.Glide;
import com.wenyu.wenyuyuedu.R;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by lenovo on 2017/3/10.
 */

public class AttentionHeadviewContentGridView extends BaseAdapter {

    private Context context;
    private List<String> mList;
    private View inflatView;
    private AttentionHeadviewContentGridView.InvitationHeadViewHolder holder;
    private ImageView viewById;

    public AttentionHeadviewContentGridView(Context context) {
        this.context = context;
        mList = new ArrayList<>();
    }

    @Override
    public int getCount() {
        return mList.size();
    }

    @Override
    public Object getItem(int i) {
        return null;
    }

    @Override
    public long getItemId(int i) {
        return 0;
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
        holder = null;
        if(view != null){
            return view;
        }
        if(view == null){
            inflatView = View.inflate(context, R.layout.attention_detail_headview_gridview, null);
            viewById = (ImageView) inflatView.findViewById(R.id.iv_photoview);
            inflatView.setTag(holder);
        }else {
            holder = (AttentionHeadviewContentGridView.InvitationHeadViewHolder)inflatView.getTag();
        }
        Glide.with(context)
                .load(mList.get(i))
                .into(viewById);

        return inflatView;
    }
    class InvitationHeadViewHolder{
        ImageView iv_photoview;
    }

    public void addAll(List<String> list) {
        if(list != null){
            mList.clear();
            mList.addAll(list);
            notifyDataSetChanged();
        }
    }
}
